<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="模版名称" prop="templateName">
        <el-input
          v-model="queryParams.templateName"
          placeholder="请输入模版名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="contractTemplateList">
      <!-- <el-table-column :formatter="defaultTableColumnDate" label="ID" align="center" prop="id" /> -->
      <el-table-column :formatter="defaultTableColumnDate" label="序号" align="center" type="index" />
      <el-table-column :formatter="defaultTableColumnDate" label="合同模版名称" align="center" prop="templateName" />
      <el-table-column :formatter="defaultTableColumnDate" label="模版描述" align="center" prop="templateDesc" />
      <el-table-column :formatter="defaultTableColumnDate" label="合同类型" align="center" prop="contractType" />
      <el-table-column :formatter="defaultTableColumnDate" label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :formatter="defaultTableColumnDate" label="操作" align="center" prop="link">
        <template slot-scope="scope">
          <el-link type="primary" @click="handleForm(scope.row)">查看</el-link>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改平台权益订单对话框 -->
    <el-dialog destroy-on-close :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="权益id" prop="rightsId">
          <el-input v-model="form.rightsId" placeholder="请输入权益id" />
        </el-form-item>
        <el-form-item label="企业id" prop="enterpriseId">
          <el-input v-model="form.enterpriseId" placeholder="请输入企业id" />
        </el-form-item>
        <el-form-item label="订单金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入订单金额" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识 0 正常 1 删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标识 0 正常 1 删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContractTemplate } from "@/api/system/contractTemplate";

export default {
  name: "contractTemplate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台权益订单表格数据
      contractTemplateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        rightsId: null,
        enterpriseId: null,
        amount: null,
        payType: null,
        status: null,
        payTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleForm(row) {
      window.open(row.templateLink)
      // getTemplateUrl({ contractUrl: row.id }).then(response => {
      //   const previewUrl = response.data.templates[0].previewUrl
      //   window.open(previewUrl)
      // })
    },
    handleClick(tab, event) {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询平台权益订单列表 */
    getList() {
      this.loading = true;
      listContractTemplate({...this.queryParams, status: this.status}).then(response => {
        this.contractTemplateList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNumber: null,
        rightsId: null,
        enterpriseId: null,
        amount: null,
        payType: null,
        status: null,
        payTime: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
